package com.hsck.order.kds.login

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.util.AttributeSet
import android.view.View

class MyProgressView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) :
    View(context, attrs, defStyleAttr) {

    private var start = 0F
    private var end = context.resources.displayMetrics.widthPixels / 3F

    private val paint by lazy {
        Paint().apply {
            color = Color.WHITE
        }

    }

    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
        canvas.drawColor(Color.GRAY)
        paint.strokeWidth = height.toFloat()

        start += 10
        end += 10
        if(start > width){
            start = 0F
        }
        if(end > width){
            end = 0F
        }
        if (end > start) {
            canvas.drawLine(start, height / 2F, end, height / 2F, paint)
        } else {
            canvas.drawLine(0F, height / 2F, end, height / 2F, paint)
            canvas.drawLine(start, height / 2F, width.toFloat(), height / 2F, paint)
        }


        postInvalidateOnAnimation()
    }
}